package com.ict.web.service.impl;

import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ict.common.core.domain.entity.SysDept;
import com.ict.common.core.domain.entity.SysUser;
import com.ict.common.utils.SecurityUtils;
import com.ict.common.utils.StringUtils;
import com.ict.common.utils.uuid.IdUtils;
import com.ict.system.mapper.SysUserRoleMapper;
import com.ict.system.service.ISysDeptService;
import com.ict.system.service.ISysDictDataService;
import com.ict.system.service.ISysUserService;
import com.ict.web.constant.Constants;
import com.ict.web.constant.ProjectStatusEnum;
import com.ict.web.controller.file.domain.YzqFile;
import com.ict.web.controller.file.service.IYzqFileService;
import com.ict.web.domain.*;
import com.ict.web.dto.ApprovalAddDto;
import com.ict.web.mapper.ApprovalMapper;
import com.ict.web.msg.domain.SysMsg;
import com.ict.web.msg.util.CreateMsgUtil;
import com.ict.web.noteConfig.NoteConfig;
import com.ict.web.service.*;
import com.ict.web.utils.pdf.RoleUtil;
import com.ict.web.vo.*;
import io.jsonwebtoken.lang.Collections;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.Assert;

import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;
import java.util.StringTokenizer;
import java.util.stream.Collectors;


/**
 * 审核Service业务层处理
 *
 * @author ruoyi
 * @date 2022-02-24
 */
@Service
public class ApprovalServiceImpl extends ServiceImpl<ApprovalMapper,Approval> implements IApprovalService
{
    @Autowired
    private ApprovalMapper approvalMapper;
    @Autowired
    private IYzqFileService fileService;
    @Autowired
    private IProjectManagementService projectManagementService;
    @Autowired
    private ISysUserService userService;
    @Autowired
    private ISysDictDataService dictDataService;
    @Autowired
    private IApprovalService approvalService;
    @Autowired
    private ISysDeptService deptService;
    @Autowired
    private IReviewTaskService reviewTaskService;
    @Autowired
    private IExpertInformationSheetService expertInformationSheetService;
    @Autowired
    private IExtractExpertService extractExpertService;
    @Autowired
    private IMilestoneInformationService milestoneInformationService;
    @Autowired
    private IFinanceService financeService;
    @Autowired
    private IContractInformationService contractInformationService;
    @Autowired
    private IComplianceService complianceService;
    @Autowired
    private IPreliminaryInformationService preliminaryInformationService;
    @Autowired
    private ILastCheckService lastCheckService;
    @Autowired
    private SysUserRoleMapper userRoleMapper;
    @Autowired
    private ProjectInfoService projectInfoService;
    @Autowired
    private IAnnualDeclarationService annualDeclarationService;
    @Autowired
    private ISupplementaryDeclarationService supplementaryDeclarationService;
    @Override
    public List<ApprovalVo> selectProjectApprovalList(Long proId) {
        ArrayList<ApprovalVo> list = new ArrayList<>();
        QueryWrapper<Approval> wrapper = new QueryWrapper<>();
        wrapper.eq("project_id",proId);
        wrapper.eq("approval_type",Approval.APPROVAL_TYPE_PROJECT_MANAGE);
        wrapper.eq("del_flag", ExtractExpert.DELETE_STATUS_NORMAL);
        wrapper.isNull("expert_id");
        wrapper.isNull("plan_id");
        List<Approval> approvals = approvalMapper.selectList(wrapper);
        ProjectManagement projectManagement = projectManagementService.getById(proId);
        List<Approval> collect2 = approvals.stream().sorted(Comparator.comparing(Approval::getStartTime)).collect(Collectors.toList());
        collect2.stream().forEach(s->{
            List<YzqFile> fileList = new ArrayList<>();
            ApprovalVo approvalVo = new ApprovalVo();
            BeanUtils.copyProperties(s,approvalVo);
            approvalVo.setApprovalStatusName(ProjectStatusEnum.getEnum(approvalVo.getApprovalStatus()).getStatusDes());
            if(StringUtils.isNotNull(approvalVo.getApprovalDatabase())){
                if(approvalVo.getApprovalDatabase().contains(",")){
                    List<String> fileNameList=new ArrayList<String>();
                    StringTokenizer st=new StringTokenizer(approvalVo.getApprovalDatabase(),",");
                    while(st.hasMoreTokens()){
                        String s1 = st.nextToken();
                        YzqFile yzqFile = fileService.getById(s1);
                        if(StringUtils.isNotNull(yzqFile)){
                            fileList.add(yzqFile);
                            String fileName = yzqFile.getFileName();
                            if(StringUtils.isNotEmpty(fileName)){
                                fileNameList.add(fileName);
                            }

                        }
                    }
                    approvalVo.setApprovalDatabaseName(String.join(";", fileNameList));
                }else {
                    YzqFile file = fileService.getById(approvalVo.getApprovalDatabase());
                    if (file!=null){
                        fileList.add(file);
                        approvalVo.setApprovalDatabaseName(file.getFileName());
                    }

                 }
                approvalVo.setRelationFile(fileList);
            }
            //返回关联资源的id
            //发改/财政审批备案id
            if (s.getApprovalNode().equals(ProjectStatusEnum.FINANCIAL_APPROVAL_AND_FILING_HAS_BEEN_PASSED.get().getNode())){
                approvalVo.setRelationId(projectManagement.getFinanceId()!=null?projectManagement.getFinanceId():null);
                if(StringUtils.isNotNull(projectManagement.getFinanceId())){
                    Finance finance = financeService.getById(projectManagement.getFinanceId());
                    List<YzqFile> listFile = new ArrayList<>();
                    if(StringUtils.isNotNull(finance)){
                        YzqFile approvalAnnexFile = fileService.getById(finance.getApprovalAnnexId());
                        if(StringUtils.isNotNull(approvalAnnexFile)){
                            listFile.add(approvalAnnexFile);
                        }
                        YzqFile approvalFinanceFile = fileService.getById(finance.getApprovalFinanceId());
                        if(StringUtils.isNotNull(approvalFinanceFile)){
                            listFile.add(approvalFinanceFile);
                        }
                        approvalVo.setRelationFile(listFile);
                    }
                }
            }
            //合同备案id
            if (s.getApprovalNode().equals(ProjectStatusEnum.CONTRACT_FILING_SUBMITTED.get().getNode())){
                approvalVo.setRelationId(projectManagement.getContractId()!=null?projectManagement.getContractId():null);
                if(StringUtils.isNotNull(projectManagement.getContractId())){
                    ContractInformation contractInformation = contractInformationService.getById(projectManagement.getContractId());
                    List<YzqFile> listFile = new ArrayList<>();
                    if(StringUtils.isNotNull(contractInformation)){
                        YzqFile file = fileService.getById(contractInformation.getScannedCopyOfContract());
                        if(StringUtils.isNotNull(file)){
                            listFile.add(file);
                        }
                        YzqFile fileTaf = fileService.getById(contractInformation.getTenderAnnouncementFileId());
                        if(StringUtils.isNotNull(fileTaf)){
                            listFile.add(fileTaf);
                        }
                        YzqFile fileBwaf = fileService.getById(contractInformation.getBidWinningAnnouncementFileId());
                        if(StringUtils.isNotNull(fileBwaf)){
                            listFile.add(fileBwaf);
                        }
                        approvalVo.setRelationFile(listFile);
                    }
                }
            }
            //里程牌id
            if (s.getApprovalNode().equals(ProjectStatusEnum.MILESTONE_MANAGEMENT_SUBMITTED.get().getNode())){
                List<MilestoneInformationVo> milestoneInformationList = milestoneInformationService.selectMilestoneInformationByProId(proId);
                List<YzqFile> listFile = new ArrayList<>();
                if(StringUtils.isNotEmpty(milestoneInformationList)){
                    milestoneInformationList.forEach(m->{
                        YzqFile fileEs = fileService.getById(m.getEnclosure());
                        if (StringUtils.isNotNull(fileEs)){
                            listFile.add(fileEs);
                        }
                    });
                    approvalVo.setRelationFile(listFile);
                    approvalVo.setRelationId(projectManagement.getProId());
                }

            }
            //合规审查id
            if (s.getApprovalNode().equals(ProjectStatusEnum.COMPLIANCE_REVIEW_SUBMITTED.get().getNode())){
                approvalVo.setRelationId(projectManagement.getComplianceId()!=null?projectManagement.getComplianceId():null);
            }
            //初验备案id
            if (s.getApprovalNode().equals(ProjectStatusEnum.PRELIMINARY_INSPECTION_AND_FILING_SUBMITTED.get().getNode())){
                approvalVo.setRelationId(projectManagement.getFirstCheckId()!=null?projectManagement.getFirstCheckId():null);
                if(StringUtils.isNotNull(projectManagement.getFirstCheckId())){
                    PreliminaryInformation preliminaryInformation = preliminaryInformationService.getById(projectManagement.getFirstCheckId());
                    List<YzqFile> listFile = new ArrayList<>();
                    if(StringUtils.isNotNull(preliminaryInformation)){
                        YzqFile file = fileService.getById(preliminaryInformation.getCertificate());
                        if(StringUtils.isNotNull(file)){
                            listFile.add(file);
                        }
                        approvalVo.setRelationFile(listFile);
                    }
                }
            }
            //终验备案id
            if (s.getApprovalNode().equals(ProjectStatusEnum.FINAL_ACCEPTANCE_RECORD_SUBMITTED.get().getNode())){
                approvalVo.setRelationId(projectManagement.getLastCheckId()!=null?projectManagement.getLastCheckId():null);
                if(StringUtils.isNotNull(projectManagement.getLastCheckId())){
                    LastCheck lastCheck = lastCheckService.getById(projectManagement.getLastCheckId());
                    List<YzqFile> listFile = new ArrayList<>();
                    if(StringUtils.isNotNull(lastCheck)){
                        YzqFile file = fileService.getById(lastCheck.getLastAdoptVoucher());
                        if(StringUtils.isNotNull(file)){
                            listFile.add(file);
                        }
                        approvalVo.setRelationFile(listFile);
                    }
                }
            }
            //现场论证id
            if (s.getApprovalNode().equals(ProjectStatusEnum.ON_SITE_DEMONSTRATION_NEEDS_TO_BE_MODIFIED.get().getNode())){
                approvalVo.setRelationId(projectManagement.getProgrammeId()!=null?projectManagement.getProgrammeId():null);
            }
            //方案修改id
            if (s.getApprovalNode().equals(ProjectStatusEnum.SCHEME_DECLARATION_UPDATE_RETURN_MODIFICATION.get().getNode())){
                approvalVo.setRelationId(projectManagement.getProgrammeId()!=null?projectManagement.getProgrammeId():null);
            }
            //方案id
            if (s.getApprovalNode().equals(ProjectStatusEnum.ON_SITE_DEMONSTRATION_RETURN_RESTATEMENT.get().getNode())){
                approvalVo.setRelationId(projectManagement.getProgrammeId()!=null?projectManagement.getProgrammeId():null);
            }
            //意见汇总id
            if (s.getApprovalNode().equals(ProjectStatusEnum.SUMMARY_AND_RETURN_OF_COMMENTS.get().getNode())){
                approvalVo.setRelationId(projectManagement.getProgrammeId()!=null?projectManagement.getProgrammeId():null);
            }
            //方案预审d
            if (s.getApprovalNode().equals(ProjectStatusEnum.PROGRAM_PREREVIEW_RETURN_FOR_RETRIAL.get().getNode())){
                approvalVo.setRelationId(projectManagement.getProgrammeId()!=null?projectManagement.getProgrammeId():null);
            }
            //方案申报id
            if (s.getApprovalNode().equals(ProjectStatusEnum.SCHEME_DECLARATION_TO_BE_SUBMITTED.get().getNode())){
                approvalVo.setRelationId(projectManagement.getProgrammeId()!=null?projectManagement.getProgrammeId():null);
            }
            //项目单位返回审核进程：意见汇总节点返回为方案预审
            if(RoleUtil.getUserRole(Constants.ROLE_TYPE_PROJECT)){
                if(s.getApprovalNode().equals(ProjectStatusEnum.SUMMARY_AND_RETURN_OF_COMMENTS.get().getNode())){
                    approvalVo.setApprovalNode("方案预审");
                }
            }
            list.add(approvalVo);
        });
        return list;
    }
    /**
     *同步项目数据到项目信息表中
     * @param projectManagement
     */
    @Override
    public void synchronizationProjectInfo(ProjectManagement projectManagement){
        ProjectInfo project = projectInfoService.getById(projectManagement.getProId());
        if(StringUtils.isNull(project)){
            ProjectInfo projectInfo = new ProjectInfo();
            of(projectInfo,projectManagement);
            projectInfoService.save(projectInfo);
        }else {
            of(project,projectManagement);
            projectInfoService.updateById(project);
        }

    }
    public void of(ProjectInfo projectInfo,ProjectManagement projectManagement){
        projectInfo.setProId(String.valueOf(projectManagement.getProId()));
        projectInfo.setProName(projectManagement.getName());
        projectInfo.setProNature(projectManagement.getNature());
        projectInfo.setProInvestmentEstimation(String.valueOf(projectManagement.getInvestmentEstimation()));
        projectInfo.setProTime(projectManagement.getCreateTime());
        projectInfo.setProStag(projectManagement.getStag());
        projectInfo.setProNode(projectManagement.getNode());
        projectInfo.setProType(projectManagement.getType());
        projectInfo.setProCompany(projectManagement.getCompany());
        projectInfo.setProState(projectManagement.getIsDelete());
        projectInfo.setUpdateTime(LocalDateTime.now());
        SysUser user = userService.selectUserById(projectManagement.getUserId());
        if(StringUtils.isNotNull(user)){
            SysDept dept = deptService.selectDeptById(user.getDeptId());
            if(StringUtils.isNotNull(dept)){
                projectInfo.setProDeptId(dept.getFormerId()!=null?dept.getFormerId():null);
                projectInfo.setProDept(dept.getDeptName());
                if(StringUtils.isNotEmpty(dept.getOrgCategory())&&dept.getOrgCategory().equals("4")){
                    projectInfo.setProSecnId(dept.getFormerId()!=null?dept.getFormerId():null);
                    projectInfo.setProSecn(dept.getDeptName());
                }
            }
        }
        if(projectManagement.getNature().equals(ProjectManagement.PROJECT_DECLARE)){
            if(StringUtils.isNotNull(projectManagement.getAnnualId())){
                AnnualDeclaration annualDeclaration = annualDeclarationService.getById(projectManagement.getAnnualId());
                if(StringUtils.isNotNull(annualDeclaration)){
                    projectInfo.setProRelationUser(annualDeclaration.getProjectContact());
                    projectInfo.setProRelationUserPhone(annualDeclaration.getContactTelephone());
                }
            }
        }else {
            if(StringUtils.isNotNull(projectManagement.getSupplementaryId())){
                SupplementaryDeclaration supplementaryDeclaration = supplementaryDeclarationService.getById(projectManagement.getSupplementaryId());
                if(StringUtils.isNotNull(supplementaryDeclaration)){
                    projectInfo.setProRelationUser(supplementaryDeclaration.getProjectContact());
                    projectInfo.setProRelationUserPhone(supplementaryDeclaration.getContactTelephone());
                }
            }
        }
    }
    @Override
    @Transactional(rollbackFor = Exception.class)
    public boolean insertApproval(ApprovalAddDto dto) {
        //todo 权限校验
        Assert.isTrue(StringUtils.isNotNull(dto.getProjectId()),"项目id不能为空");
        ProjectManagement projectManagement = projectManagementService.getById(dto.getProjectId());
        Assert.isTrue(StringUtils.isNotNull(projectManagement),"未找到该项目");
        ApproveProgressVo anEnum = ProjectStatusEnum.getEnum(projectManagement.getIsState());
        Assert.isTrue(anEnum.getStatusDes().equals("待审核")
                        ||anEnum.getStatusDes().equals("待审批")
                        ||anEnum.getStatusDes().equals("退回重申"),
//                        ||anEnum.getStatus().equals(ProjectStatusEnum.ON_SITE_DEMONSTRATION_RETURN_RESTATEMENT.get().getStatus()
                "不处于待审核或者待审批状态 不能审核");
        Long userId = SecurityUtils.getUserId();
        Long deptId = SecurityUtils.getDeptId();
        String nickName=userService.selectUserById(userId).getNickName();
        List<Approval> approvalList = new ArrayList<>();
        Approval approval = approvalService.getApproval(projectManagement.getProId(), projectManagement.getIsState(),null,null);
        if(StringUtils.isNotNull(dto.getApprovalOpinion())){
            approval.setApprovalOpinion(dto.getApprovalOpinion());
        }
        approval.setApprovalResult(dto.getApprovalResult());
        approval.setApprovalStatus(dto.getApprovalStatus());
        approval.setApprovalOperator(nickName);
        approval.setEndTime(LocalDateTime.now());
        approval.setApprovalType(Approval.APPROVAL_TYPE_PROJECT_MANAGE);

        SysDept sysDept = deptService.selectDeptById(SecurityUtils.getDeptId());
        //申报审核
        if(ProjectStatusEnum.APPLICATION_REVIEW_TO_BE_REVIEWED.get().getStatus().equals(projectManagement.getIsState())){

            if(Constants.APPLICATION_REVIEW_PASSED.equals(dto.getApprovalStatus())){
                //通过 更新项目申报申报审核通过进程
                approval.setApprovalNode(ProjectStatusEnum.APPLICATION_REVIEW_PASSED.get().getNode());
                approval.setApprovalStage(ProjectStatusEnum.APPLICATION_REVIEW_PASSED.get().getStage());
                approval.setApprovalResult(sysDept.getDeptName()+CreateMsgUtil.APPROVAL_RESULT+ProjectStatusEnum.APPLICATION_REVIEW_PASSED.get().getStatusDes());
                if (projectManagement.getType().equals("0")||projectManagement.getType().equals("1")||projectManagement.getType().equals("2")||projectManagement.getType().equals("4")) {

                    //新增方案申报进程
                    Approval approvalScheme = new Approval(IdUtils.snowId(),projectManagement.getProId(),ProjectStatusEnum.SCHEME_DECLARATION_TO_BE_SUBMITTED.get().getStage(),
                            ProjectStatusEnum.SCHEME_DECLARATION_TO_BE_SUBMITTED.get().getNode(),LocalDateTime.now(),null,null,ProjectStatusEnum.SCHEME_DECLARATION_TO_BE_SUBMITTED.get().getStatus(),
                            "/",null, null,null, LocalDateTime.now(),Approval.APPROVAL_TYPE_PROJECT_MANAGE);
                    approvalList.add(approvalScheme);
                    //同步项目的状态为方案申报和节点为方案申报
                    projectManagement.setStag(ProjectStatusEnum.SCHEME_DECLARATION_TO_BE_SUBMITTED.get().getStage());
                    projectManagement.setNode(ProjectStatusEnum.SCHEME_DECLARATION_TO_BE_SUBMITTED.get().getNode());
                    projectManagement.setIsState(ProjectStatusEnum.SCHEME_DECLARATION_TO_BE_SUBMITTED.get().getStatus());
                }else if(projectManagement.getType().equals("3")){
                    //同步项目的状态为项目申报和节点为方案申报
                    projectManagement.setStag(ProjectStatusEnum.APPLICATION_REVIEW_PASSED.get().getStage());
                    projectManagement.setNode(ProjectStatusEnum.APPLICATION_REVIEW_PASSED.get().getNode());
                    projectManagement.setIsState(ProjectStatusEnum.APPLICATION_REVIEW_PASSED.get().getStatus());
                }

                //申报审核通过-生成对应系统消息
                String content=CreateMsgUtil.PERSON+projectManagement.getName()+CreateMsgUtil.openToSocialMap.get(CreateMsgUtil.APPROVAL_RESULT_PASSED);
                CreateMsgUtil.createMsg(content,projectManagement.getUserId(),null,CreateMsgUtil.APPROVAL_RESULT_TITLE, SysMsg.RESOURCE_TYPE_UNIT,null, null);
                //同步项目数据到项目信息表中
                synchronizationProjectInfo(projectManagement);
            }else if(Constants.APPLICATION_REVIEW_RETURN_MODIFICATION.equals(dto.getApprovalStatus())){
                //退回修改：审核状态更新为退回修改，新增一个申报修改节点，项目状态为审核修改待提交
                approval.setApprovalNode(ProjectStatusEnum.APPLICATION_REVIEW_RETURN_MODIFICATION.get().getNode());
                approval.setApprovalStage(ProjectStatusEnum.APPLICATION_REVIEW_RETURN_MODIFICATION.get().getStage());
                approval.setEndTime(null);
                approval.setApprovalOperator(SecurityUtils.getNickName());
                approval.setApprovalResult(sysDept.getDeptName()+ CreateMsgUtil.APPROVAL_RESULT+ProjectStatusEnum.APPLICATION_REVIEW_RETURN_MODIFICATION.get().getStatusDes()+dto.getApprovalOpinion());
                projectManagement.setIsState(ProjectStatusEnum.APPLICATION_REVIEW_RETURN_MODIFICATION.get().getStatus());
                projectManagement.setNode(ProjectStatusEnum.APPLICATION_REVIEW_RETURN_MODIFICATION.get().getNode());
               //申报审核退回修改-生成对应系统消息
                String content=CreateMsgUtil.PERSON+projectManagement.getName()+CreateMsgUtil.openToSocialMap.get(CreateMsgUtil.APPROVAL_RESULT_MODIFICATION);
                CreateMsgUtil.createMsg(content,projectManagement.getUserId(),null,CreateMsgUtil.APPROVAL_RESULT_TITLE, SysMsg.RESOURCE_TYPE_UNIT,null, null);

            }else {
                //驳回
                approval.setApprovalNode(ProjectStatusEnum.APPLICATION_REVIEW_REJECT.get().getNode());
                approval.setApprovalStage(ProjectStatusEnum.APPLICATION_REVIEW_REJECT.get().getStage());
                approval.setApprovalResult(sysDept.getDeptName()+CreateMsgUtil.APPROVAL_RESULT+ProjectStatusEnum.APPLICATION_REVIEW_REJECT.get().getStatusDes());
                projectManagement.setIsState(ProjectStatusEnum.APPLICATION_REVIEW_REJECT.get().getStatus());
                //申报审核驳回-生成对应系统消息
                String content=CreateMsgUtil.PERSON+projectManagement.getName()+CreateMsgUtil.openToSocialMap.get(CreateMsgUtil.APPROVAL_RESULT_REJECT);
                CreateMsgUtil.createMsg(content,projectManagement.getUserId(),null,CreateMsgUtil.APPROVAL_RESULT_TITLE, SysMsg.RESOURCE_TYPE_UNIT,null, null);
            }

        }
        //申报修改
        if(ProjectStatusEnum.APPLICATION_UPDATE_TO_BE_APPROVED.get().getStatus().equals(projectManagement.getIsState())){
            //通过：更新项目申报申报修改通过进程、新增方案申报待提交进程、同步项目的状态为方案申报和节点为方案申报
            if(ProjectStatusEnum.APPLICATION_REVIEW_PASSED.get().getStatus().equals(dto.getApprovalStatus())){
                approval.setApprovalOperator(nickName);
                approval.setApprovalNode(ProjectStatusEnum.APPLICATION_REVIEW_PASSED.get().getNode());
                approval.setApprovalStage(ProjectStatusEnum.APPLICATION_REVIEW_PASSED.get().getStage());
                approval.setApprovalResult(sysDept.getDeptName()+CreateMsgUtil.APPROVAL_RESULT+ProjectStatusEnum.APPLICATION_REVIEW_PASSED.get().getStatusDes());
                if (projectManagement.getType().equals("0")||projectManagement.getType().equals("1")||projectManagement.getType().equals("2")) {
                    Approval approvalScheme = new Approval(IdUtils.snowId(),projectManagement.getProId(),ProjectStatusEnum.SCHEME_DECLARATION_TO_BE_SUBMITTED.get().getStage(),
                            ProjectStatusEnum.SCHEME_DECLARATION_TO_BE_SUBMITTED.get().getNode(),LocalDateTime.now(),null,nickName,ProjectStatusEnum.SCHEME_DECLARATION_TO_BE_SUBMITTED.get().getStatus(),
                            "/",null, null,null, LocalDateTime.now(),Approval.APPROVAL_TYPE_PROJECT_MANAGE);
                    approvalList.add(approvalScheme);

                    projectManagement.setStag(ProjectStatusEnum.SCHEME_DECLARATION_TO_BE_SUBMITTED.get().getStage());
                    projectManagement.setNode(ProjectStatusEnum.SCHEME_DECLARATION_TO_BE_SUBMITTED.get().getNode());
                    projectManagement.setIsState(ProjectStatusEnum.SCHEME_DECLARATION_TO_BE_SUBMITTED.get().getStatus());
                    //同步项目数据到项目信息表中
                    synchronizationProjectInfo(projectManagement);
                } else if (projectManagement.getType().equals("3")||projectManagement.getType().equals("4")) {
                    projectManagement.setStag(ProjectStatusEnum.APPLICATION_UPDATE_PASSED.get().getStage());
                    projectManagement.setNode(ProjectStatusEnum.APPLICATION_UPDATE_PASSED.get().getNode());
                    projectManagement.setIsState(ProjectStatusEnum.APPLICATION_UPDATE_PASSED.get().getStatus());
                }
            //退回修改：审核状态更新为退回修改，项目状态为审核修改待提交
            }else if(ProjectStatusEnum.APPLICATION_REVIEW_RETURN_MODIFICATION.get().getStatus().equals(dto.getApprovalStatus())){
                approval.setApprovalNode(ProjectStatusEnum.APPLICATION_UPDATE_RETURN_MODIFICATION.get().getNode());
                approval.setApprovalStage(ProjectStatusEnum.APPLICATION_UPDATE_RETURN_MODIFICATION.get().getStage());
                approval.setEndTime(null);
                approval.setApprovalOperator(nickName);
                approval.setApprovalResult(sysDept.getDeptName()+ CreateMsgUtil.APPROVAL_RESULT+ProjectStatusEnum.APPLICATION_UPDATE_TO_BE_SUBMITTED.get().getStatusDes()+dto.getApprovalOpinion());
                projectManagement.setIsState(ProjectStatusEnum.APPLICATION_UPDATE_RETURN_MODIFICATION.get().getStatus());
                projectManagement.setNode(ProjectStatusEnum.APPLICATION_UPDATE_RETURN_MODIFICATION.get().getNode());
            //驳回
            } else if (ProjectStatusEnum.APPLICATION_REVIEW_REJECT.get().getStatus().equals(dto.getApprovalStatus())) {
                approval.setApprovalNode(ProjectStatusEnum.APPLICATION_UPDATE_TURN_DOWN.get().getNode());
                approval.setApprovalStage(ProjectStatusEnum.APPLICATION_UPDATE_TURN_DOWN.get().getStage());
                approval.setApprovalOperator(nickName);
                approval.setApprovalResult(sysDept.getDeptName()+ CreateMsgUtil.APPROVAL_RESULT+ProjectStatusEnum.APPLICATION_UPDATE_TURN_DOWN.get().getStatusDes()+dto.getApprovalOpinion());
                projectManagement.setIsState(ProjectStatusEnum.APPLICATION_UPDATE_TURN_DOWN.get().getStatus());
                projectManagement.setNode(ProjectStatusEnum.APPLICATION_UPDATE_TURN_DOWN.get().getNode());
            }
        }
        //专家在线预审审核
        if(ProjectStatusEnum.ONLINE_PREQUALIFICATION_PENDING_APPROVAL.get().getStatus().equals(projectManagement.getIsState())){
            //部门为评审专家
            Assert.isTrue(RoleUtil.getUserRole(Constants.ROLE_TYPE_EXPERT),"该用户不是专家，没审核权限");
            approval.setApprovalOperator(null);
            approval.setApprovalOpinion(null);
            List<ExpertInformationSheet> list = expertInformationSheetService.lambdaQuery().eq(ExpertInformationSheet::getUserId, SecurityUtils.getUserId())
                    .eq(ExpertInformationSheet::getDelFlag, ExtractExpert.DELETE_STATUS_NORMAL).list();
            Assert.isTrue(!Collections.isEmpty(list),"未找到该用户对应的专家信息");
            Assert.isTrue(list.size()!=0,"该用户未绑定专家，无法审核");
            Assert.isTrue(list.size()==1,"该用户下有多个专家信息，无法审核");
            Long reviewTaskId = projectManagement.getReviewTaskId();
            Assert.isTrue(StringUtils.isNotNull(reviewTaskId),"项目未关联相关评审任务");
            ReviewTask reviewTask = reviewTaskService.getById(reviewTaskId);
            ExtractExpert extractExpert = reviewTaskService.extractExpertByReviewTaskId(reviewTaskId, list.get(0).getExpertId());
            //更新专家审批进程为在线预审已审批
            List<Approval> expertApprovalList = approvalMapper.selectList(new QueryWrapper<Approval>()
                    .eq("project_id", projectManagement.getProId())
                    .eq("approval_status", ProjectStatusEnum.ONLINE_PREQUALIFICATION_PENDING_APPROVAL.get().getStatus())
                    .eq("expert_id", extractExpert.getExpertId())
                    .orderByDesc("approval_id"));
            Approval expertApproval = expertApprovalList.get(0);
            if(StringUtils.isNotNull(dto.getApprovalResult())){
                if(dto.getApprovalResult().equals(Approval.APPROVAL_RESULT_PASS)){
                    expertApproval.setApprovalResult("通过");
                }
                if(dto.getApprovalResult().equals(Approval.APPROVAL_RESULT_BACK_UPDATE)){
                    expertApproval.setApprovalResult("退回重申");
                }
            }
            expertApproval.setApprovalStatus(ProjectStatusEnum.ONLINE_PREQUALIFICATION_APPROVED.get().getStatus());
            expertApproval.setApprovalOpinion(dto.getApprovalOpinion());
            expertApproval.setApprovalStage(anEnum.getStage());
            expertApproval.setEndTime(LocalDateTime.now());
            if (StringUtils.isNotNull(dto.getApprovalDatabase())){//添加专家审批文件
                ArrayList<YzqFile> fileList = ApprovalAddDto.toFile(expertApproval, dto);
                fileService.batchInsertFile(fileList);
            }
            approvalMapper.updateById(expertApproval);
            //更新抽取表中专家节点状态
            extractExpert.setExtractNode(ProjectStatusEnum.ONLINE_PREQUALIFICATION_APPROVED.get().getStatus());
            extractExpert.setStatus(ExtractExpert.STATUS_APPLY_APPROVAL);
            //所有专家接受在线预审：更新项目审核进程为已审批并新增项目为意见汇总审批审核进程、更新项目为意见汇总待审核
            ReviewTaskDetailVo reviewTaskDetailVo = reviewTaskService.reviewTaskDetailByProId(projectManagement.getProId());
            Assert.isTrue(StringUtils.isNotNull(reviewTaskDetailVo),"未找到该项目的评审任务");
            List<ExtractExpertDetailVo> extractExpertList = reviewTaskDetailVo.getExtractExpertList();
            List<ExtractExpertDetailVo> collect = extractExpertList.stream().filter(
                                            s -> s.getExtractNode().equals(ProjectStatusEnum.ONLINE_PREQUALIFICATION_APPROVED.get().getStatus())).collect(Collectors.toList());
            if(reviewTaskDetailVo.getExpertNum().equals(String.valueOf(collect.size()+1))){
                //评审会议详情
                ReviewTaskVo reviewTaskVo = new ReviewTaskVo(reviewTask.getReviewTimeStart(),reviewTask.getReviewTimeEnd(),reviewTask.getReviewAddress());
                String string = JSON.toJSONString(reviewTaskVo);
                //项目的审核状态为意见汇总待审批
                approval.setApprovalStatus(ProjectStatusEnum.ONLINE_PREQUALIFICATION_APPROVED.get().getStatus());
                approvalService.dealStayApproval(projectManagement.getProId(),ProjectStatusEnum.ONLINE_PREQUALIFICATION_PENDING_APPROVAL.get().getStatus(),
                        ProjectStatusEnum.ONLINE_PREQUALIFICATION_APPROVED.get().getStatus(),null,null,null,null);
                Approval approval1 = new Approval(IdUtils.snowId(), projectManagement.getProId(), ProjectStatusEnum.COMMENTS_SUMMARY_TO_BE_APPROVED.get().getStage(),
                        ProjectStatusEnum.COMMENTS_SUMMARY_TO_BE_APPROVED.get().getNode(), LocalDateTime.now(), null, null, ProjectStatusEnum.COMMENTS_SUMMARY_TO_BE_APPROVED.get().getStatus(),
                        string, null, null, null, LocalDateTime.now(), Approval.APPROVAL_TYPE_PROJECT_MANAGE);
                  //项目单位详情需求：项目单位意见汇总修改时间改为项目单位上一个在线预审的时间
                List<Approval> approvals = approvalService.lambdaQuery().eq(Approval::getApprovalType, Approval.APPROVAL_TYPE_PROJECT_MANAGE)
                        .eq(Approval::getProjectId, projectManagement.getProId())
                        .orderByDesc(Approval::getCreateTime).list();
                approval1.setUpdateTime(approvals.get(0).getCreateTime());
                approvalService.save(approval1);
                projectManagement.setIsState(ProjectStatusEnum.COMMENTS_SUMMARY_TO_BE_APPROVED.get().getStatus());
                projectManagement.setNode(ProjectStatusEnum.COMMENTS_SUMMARY_TO_BE_APPROVED.get().getNode());
                projectManagement.setStag(ProjectStatusEnum.COMMENTS_SUMMARY_TO_BE_APPROVED.get().getStage());
                reviewTask.setNode(ProjectStatusEnum.COMMENTS_SUMMARY_TO_BE_APPROVED.get().getNode());
                reviewTask.setNodeStatus(ProjectStatusEnum.COMMENTS_SUMMARY_TO_BE_APPROVED.get().getStatus());
                reviewTaskService.updateById(reviewTask);
                extractExpert.setExtractNode(ProjectStatusEnum.ON_SITE_DEMONSTRATION_TO_BE_REVIEWED.get().getStatus());
                extractExpert.setStatus(ExtractExpert.STATUS_NOT_START);
                //抽取表下所有抽取出的状态为待开始
                List<ExtractExpert> arrayList = new ArrayList<>();
                List<ExtractExpert> extractExperts = reviewTaskService.getExtractExpertList(reviewTaskId);
                Assert.isTrue(StringUtils.isNotEmpty(extractExperts),"该评审任务未找到专家抽取表信息");
                extractExperts.stream().forEach(s->{
                    ExtractExpert expert = new ExtractExpert();
                    BeanUtils.copyProperties(s,expert);
                    expert.setStatus(ExtractExpert.STATUS_NOT_START);
                    expert.setExtractNode(Constants.ON_SITE_DEMONSTRATION_TO_BE_REVIEWED);
                    arrayList.add(expert);
                });
                extractExpertService.saveOrUpdateBatch(arrayList);
            }
            extractExpertService.updateById(extractExpert);
            //同步项目数据到项目信息表中
            synchronizationProjectInfo(projectManagement);
        }
        //意见汇总审核
        if(ProjectStatusEnum.COMMENTS_SUMMARY_TO_BE_APPROVED.get().getStatus().equals(projectManagementService.getById(dto.getProjectId()).getIsState())){
            Long reviewTaskId = projectManagement.getReviewTaskId();
            Assert.isTrue(StringUtils.isNotNull(reviewTaskId),"项目未关联相关评审任务");
            ReviewTask reviewTask = reviewTaskService.getById(reviewTaskId);
            //添加意见汇总审批文件
            if (StringUtils.isNotNull(dto.getApprovalDatabase())){
                ArrayList<YzqFile> fileList = ApprovalAddDto.toFile(approval, dto);
                fileService.batchInsertFile(fileList);
            }
            //三方机构意见汇总审核
            if(RoleUtil.getUserRole(Constants.ROLE_TYPE_THIRD)){
                //通过  新增意见汇总通过进程
                if(Constants.OPINION_SUMMARY_APPROVED.equals(dto.getApprovalStatus())){
                    approval.setApprovalNode(ProjectStatusEnum.OPINION_SUMMARY_APPROVED.get().getNode());
                    approval.setApprovalStage(ProjectStatusEnum.OPINION_SUMMARY_APPROVED.get().getStage());
                    approval.setApprovalStatus(ProjectStatusEnum.OPINION_SUMMARY_APPROVED.get().getStatus());
                    //新增现场论证进程
                    Approval approvalSite = new Approval(IdUtils.snowId(),projectManagement.getProId(),ProjectStatusEnum.ON_SITE_DEMONSTRATION_TO_BE_REVIEWED.get().getStage(),
                            ProjectStatusEnum.ON_SITE_DEMONSTRATION_TO_BE_REVIEWED.get().getNode(),LocalDateTime.now(),null,nickName,ProjectStatusEnum.ON_SITE_DEMONSTRATION_TO_BE_REVIEWED.get().getStatus(),
                            "/",null, null,null, LocalDateTime.now(),Approval.APPROVAL_TYPE_PROJECT_MANAGE);
                    approvalList.add(approvalSite);
                    //同步项目的节点为意见汇总
                    projectManagement.setIsState(ProjectStatusEnum.ON_SITE_DEMONSTRATION_TO_BE_REVIEWED.get().getStatus());
                    projectManagement.setNode(ProjectStatusEnum.ON_SITE_DEMONSTRATION_TO_BE_REVIEWED.get().getNode());
                    projectManagement.setStag(ProjectStatusEnum.ON_SITE_DEMONSTRATION_TO_BE_REVIEWED.get().getStage());
                    //同步评审任务节点
                    reviewTask.setNode(ProjectStatusEnum.ON_SITE_DEMONSTRATION_TO_BE_REVIEWED.get().getNode());
                    reviewTask.setNodeStatus(ProjectStatusEnum.ON_SITE_DEMONSTRATION_TO_BE_REVIEWED.get().getStatus());
                    //每个专家生成现场论证审核进程
                    ReviewTaskDetailVo reviewTaskDetailVo = reviewTaskService.reviewTaskDetailByProId(projectManagement.getProId());
                    Assert.isTrue(StringUtils.isNotNull(reviewTaskDetailVo),"未找到该项目的评审任务");
                    List<ExtractExpertDetailVo> extractExpertList = reviewTaskDetailVo.getExtractExpertList();
                    List<Approval> approvalArrayList = new ArrayList<>();
                    extractExpertList.stream().forEach(s->{
                        Approval approval1=
                                new Approval(IdUtils.snowId(),projectManagement.getProId(),ProjectStatusEnum.ON_SITE_DEMONSTRATION_TO_BE_REVIEWED.get().getStage(),
                                        ProjectStatusEnum.ON_SITE_DEMONSTRATION_TO_BE_REVIEWED.get().getNode(),LocalDateTime.now(),null,nickName,ProjectStatusEnum.ON_SITE_DEMONSTRATION_TO_BE_REVIEWED.get().getStatus(),
                                        "/",null, null,null, LocalDateTime.now(),Approval.APPROVAL_TYPE_EXPERT,s.getExpertId(),null);
                        approvalArrayList.add(approval1);
                    });
                    approvalService.batchApproval(approvalArrayList);
                    //同步项目数据到项目信息表中
                    synchronizationProjectInfo(projectManagement);
                }else {
                    //退回重申
                    approval.setApprovalNode(ProjectStatusEnum.SUMMARY_AND_RETURN_OF_COMMENTS.get().getNode());
                    approval.setApprovalStage(ProjectStatusEnum.SUMMARY_AND_RETURN_OF_COMMENTS.get().getStage());
                    approval.setApprovalStatus(ProjectStatusEnum.SUMMARY_AND_RETURN_OF_COMMENTS.get().getStatus());
                    projectManagement.setIsState(ProjectStatusEnum.BIG_DATA_AUDIT_COMMENTS_SUMMARY_TO_BE_APPROVED.get().getStatus());
                    projectManagement.setNode(ProjectStatusEnum.BIG_DATA_AUDIT_COMMENTS_SUMMARY_TO_BE_APPROVED.get().getNode());
                    projectManagement.setStag(ProjectStatusEnum.BIG_DATA_AUDIT_COMMENTS_SUMMARY_TO_BE_APPROVED.get().getStage());
                    //同步评审任务节点
                    reviewTask.setNode(ProjectStatusEnum.BIG_DATA_AUDIT_COMMENTS_SUMMARY_TO_BE_APPROVED.get().getNode());
                    reviewTask.setNodeStatus(ProjectStatusEnum.BIG_DATA_AUDIT_COMMENTS_SUMMARY_TO_BE_APPROVED.get().getStatus());

                    //添加大数据局审核进程
                    Approval approvalBigDataAudit = new Approval(IdUtils.snowId(), projectManagement.getProId(), ProjectStatusEnum.BIG_DATA_AUDIT_COMMENTS_SUMMARY_TO_BE_APPROVED.get().getStage(),
                            ProjectStatusEnum.BIG_DATA_AUDIT_COMMENTS_SUMMARY_TO_BE_APPROVED.get().getNode(), LocalDateTime.now(), null, null, ProjectStatusEnum.BIG_DATA_AUDIT_COMMENTS_SUMMARY_TO_BE_APPROVED.get().getStatus(),
                            "/", null, null, null, LocalDateTime.now(), Approval.APPROVAL_TYPE_PROJECT_MANAGE);
                    approvalList.add(approvalBigDataAudit);
                }
                reviewTaskService.updateById(reviewTask);
            }
            //大数据局/三方机构意见汇总
            if(RoleUtil.getUserRole(Constants.ROLE_TYPE_BIGDATA)){
                if(ProjectStatusEnum.OPINION_SUMMARY_APPROVED.get().getStatus().equals(dto.getApprovalStatus())){
                    //通过
                    approval.setApprovalNode(ProjectStatusEnum.OPINION_SUMMARY_APPROVED.get().getNode());
                    approval.setApprovalStage(ProjectStatusEnum.OPINION_SUMMARY_APPROVED.get().getStage());
                    approval.setEndTime(LocalDateTime.now());
                    //新增现场论证进程
                    Approval approvalSite = new Approval(IdUtils.snowId(),projectManagement.getProId(),ProjectStatusEnum.ON_SITE_DEMONSTRATION_TO_BE_REVIEWED.get().getStage(),
                            ProjectStatusEnum.ON_SITE_DEMONSTRATION_TO_BE_REVIEWED.get().getNode(),LocalDateTime.now(),null,null,ProjectStatusEnum.ON_SITE_DEMONSTRATION_TO_BE_REVIEWED.get().getStatus(),
                            "/",null, null,null, LocalDateTime.now(),Approval.APPROVAL_TYPE_PROJECT_MANAGE);
                    approvalList.add(approvalSite);
                    //同步项目的节点为意见汇总
                    projectManagement.setIsState(ProjectStatusEnum.ON_SITE_DEMONSTRATION_TO_BE_REVIEWED.get().getStatus());
                    projectManagement.setNode(ProjectStatusEnum.ON_SITE_DEMONSTRATION_TO_BE_REVIEWED.get().getNode());
                    projectManagement.setStag(ProjectStatusEnum.ON_SITE_DEMONSTRATION_TO_BE_REVIEWED.get().getStage());
                    //同步评审任务节点
                    reviewTask.setNode(ProjectStatusEnum.ON_SITE_DEMONSTRATION_TO_BE_REVIEWED.get().getNode());
                    reviewTask.setNodeStatus(ProjectStatusEnum.ON_SITE_DEMONSTRATION_TO_BE_REVIEWED.get().getStatus());
                    //每个专家生成现场论证审核进程
                    ReviewTaskDetailVo reviewTaskDetailVo = reviewTaskService.reviewTaskDetailByProId(projectManagement.getProId());
                    Assert.isTrue(StringUtils.isNotNull(reviewTaskDetailVo),"未找到该项目的评审任务");
                    List<ExtractExpertDetailVo> extractExpertList = reviewTaskDetailVo.getExtractExpertList();
                    List<Approval> approvalArrayList = new ArrayList<>();
                    extractExpertList.stream().forEach(s->{
                        Approval approval1=
                                new Approval(IdUtils.snowId(),projectManagement.getProId(),ProjectStatusEnum.ON_SITE_DEMONSTRATION_TO_BE_REVIEWED.get().getStage(),
                                        ProjectStatusEnum.ON_SITE_DEMONSTRATION_TO_BE_REVIEWED.get().getNode(),LocalDateTime.now(),null,nickName,ProjectStatusEnum.ON_SITE_DEMONSTRATION_TO_BE_REVIEWED.get().getStatus(),
                                        "/",null, null,null, LocalDateTime.now(),Approval.APPROVAL_TYPE_EXPERT,s.getExpertId(),null);
                        approvalArrayList.add(approval1);
                        //TODO 对接短信
                        ExpertInformationSheet expertInfo = expertInformationSheetService.getById(s.getExpertId());
                        DateTimeFormatter df=DateTimeFormatter.ofPattern("yyyy年MM月dd日 HH:mm");
                        if(StringUtils.isNotNull(expertInfo)){
                            LocalDateTime reviewTimeStart = reviewTask.getReviewTimeStart();
                            if(StringUtils.isNotEmpty(expertInfo.getPhoneNumber())){
                                CodeVo code = NoteConfig.getCode();
                                String content= NoteConfig.TITLE+expertInfo.getExpertName()+NoteConfig.EXPORTS+projectManagement.getName()+NoteConfig.DEMONSTRATION_MASSAGE_TIME+df.format(reviewTask.getReviewTimeStart())+NoteConfig.DEMONSTRATION_MASSAGE;
//                                NoteConfig.getNote(content,expertInfo.getPhoneNumber());
                            }
                        }
                    });
                    approvalService.batchApproval(approvalArrayList);
                    //同步项目数据到项目信息表中
                    synchronizationProjectInfo(projectManagement);
                }else if(ProjectStatusEnum.SUMMARY_AND_RETURN_OF_COMMENTS.get().getStatus().equals(dto.getApprovalStatus())){
                    //退回重申：项目状态为意见汇总退回重申
                    approval.setApprovalNode(ProjectStatusEnum.SUMMARY_AND_RETURN_OF_COMMENTS.get().getNode());
                    approval.setApprovalStage(ProjectStatusEnum.SUMMARY_AND_RETURN_OF_COMMENTS.get().getStage());
                    approval.setEndTime(null);
                    projectManagement.setIsState(ProjectStatusEnum.SUMMARY_AND_RETURN_OF_COMMENTS.get().getStatus());
                    projectManagement.setNode(ProjectStatusEnum.SUMMARY_AND_RETURN_OF_COMMENTS.get().getNode());
                    projectManagement.setStag(ProjectStatusEnum.SUMMARY_AND_RETURN_OF_COMMENTS.get().getStage());
                    //同步评审任务节点
                    reviewTask.setNode(ProjectStatusEnum.SUMMARY_AND_RETURN_OF_COMMENTS.get().getNode());
                    reviewTask.setNodeStatus(ProjectStatusEnum.SUMMARY_AND_RETURN_OF_COMMENTS.get().getStatus());
                }else {
                    Assert.isTrue(false,"approvalStatus值传入有误！通过=14；退出重申=15");
                }
                reviewTaskService.updateById(reviewTask);
            }

        }
        //三方预审审核
        if (ProjectStatusEnum.BIG_DATA_AUDIT_COMMENTS_SUMMARY_TO_BE_APPROVED.get().getStatus().equals(projectManagementService.getById(dto.getProjectId()).getIsState())){
            Long reviewTaskId = projectManagement.getReviewTaskId();
            Assert.isTrue(StringUtils.isNotNull(reviewTaskId),"项目未关联相关评审任务");
            ReviewTask reviewTask = reviewTaskService.getById(reviewTaskId);
            if (Constants.BIG_DATA_AUDIT_COMMENTS_SUMMARY_TO_BE_APPROVED.equals(dto.getApprovalStatus())) {
                //通过  进入
                approval.setApprovalNode(ProjectStatusEnum.BIG_DATA_AUDIT_OPINION_SUMMARY_APPROVED.get().getNode());
                approval.setApprovalStage(ProjectStatusEnum.BIG_DATA_AUDIT_OPINION_SUMMARY_APPROVED.get().getStage());
                approval.setApprovalStatus(ProjectStatusEnum.BIG_DATA_AUDIT_OPINION_SUMMARY_APPROVED.get().getStatus());
                //同步项目的节点为退回重申
                projectManagement.setIsState(ProjectStatusEnum.SUMMARY_AND_RETURN_OF_COMMENTS.get().getStatus());
                projectManagement.setNode(ProjectStatusEnum.SUMMARY_AND_RETURN_OF_COMMENTS.get().getNode());
                projectManagement.setStag(ProjectStatusEnum.SUMMARY_AND_RETURN_OF_COMMENTS.get().getStage());
                //同步评审任务节点
                reviewTask.setNode(ProjectStatusEnum.BIG_DATA_AUDIT_OPINION_SUMMARY_APPROVED.get().getNode());
                reviewTask.setNodeStatus(ProjectStatusEnum.BIG_DATA_AUDIT_OPINION_SUMMARY_APPROVED.get().getStatus());
            } else if (Constants.BIG_DATA_AUDIT_SUMMARY_AND_RETURN_OF_COMMENTS.equals(dto.getApprovalStatus())) {
                //退回重审  进入意见汇总-待审批状态
                approval.setApprovalNode(ProjectStatusEnum.BIG_DATA_AUDIT_SUMMARY_AND_RETURN_OF_COMMENTS.get().getNode());
                approval.setApprovalStage(ProjectStatusEnum.BIG_DATA_AUDIT_SUMMARY_AND_RETURN_OF_COMMENTS.get().getStage());
                approval.setApprovalStatus(ProjectStatusEnum.BIG_DATA_AUDIT_SUMMARY_AND_RETURN_OF_COMMENTS.get().getStatus());
                //新增意见汇总-待审批
                Approval approvalSite = new Approval(IdUtils.snowId(),projectManagement.getProId(),ProjectStatusEnum.COMMENTS_SUMMARY_TO_BE_APPROVED.get().getStage(),
                        ProjectStatusEnum.COMMENTS_SUMMARY_TO_BE_APPROVED.get().getNode(),LocalDateTime.now(),null,null,ProjectStatusEnum.COMMENTS_SUMMARY_TO_BE_APPROVED.get().getStatus(),
                        "/",null, null,null, LocalDateTime.now(),Approval.APPROVAL_TYPE_PROJECT_MANAGE);
                approvalList.add(approvalSite);
                //同步项目的节点为意见汇总
                projectManagement.setIsState(ProjectStatusEnum.COMMENTS_SUMMARY_TO_BE_APPROVED.get().getStatus());
                projectManagement.setNode(ProjectStatusEnum.COMMENTS_SUMMARY_TO_BE_APPROVED.get().getNode());
                projectManagement.setStag(ProjectStatusEnum.COMMENTS_SUMMARY_TO_BE_APPROVED.get().getStage());
                //同步评审任务节点
                reviewTask.setNode(ProjectStatusEnum.COMMENTS_SUMMARY_TO_BE_APPROVED.get().getNode());
                reviewTask.setNodeStatus(ProjectStatusEnum.COMMENTS_SUMMARY_TO_BE_APPROVED.get().getStatus());
            }
            reviewTaskService.updateById(reviewTask);
        }
//        现场论证审核
        if(ProjectStatusEnum.ON_SITE_DEMONSTRATION_TO_BE_REVIEWED.get().getStatus().equals(projectManagementService.getById(dto.getProjectId()).getIsState())){
            Long reviewTaskId = projectManagement.getReviewTaskId();
            Assert.isTrue(StringUtils.isNotNull(reviewTaskId),"项目未关联相关评审任务");
            ReviewTask reviewTask = reviewTaskService.getById(reviewTaskId);
            Assert.isTrue(StringUtils.isNotNull(dto.getApprovalDatabase()),"专家签字扫码件未上传");
            //同步资料库信息
            if (StringUtils.isNotNull(dto.getApprovalDatabase())){
                ArrayList<YzqFile> fileList = ApprovalAddDto.toFile(approval, dto);
                fileService.batchInsertFile(fileList);
            }
            //通过 新增通过的进程
            //是否转给第三方 有则新增三方审批进程  无则新增发改/财政审批备案进程
            if (reviewTask.getIfExchangeThird().equals("1")) {
                //转三方
                if(Constants.THE_ONSITE_DEMONSTRATION_HAS_BEEN_PASSED.equals(dto.getApprovalStatus())){
                    //通过
                    approval.setApprovalNode(ProjectStatusEnum.THE_ONSITE_DEMONSTRATION_HAS_BEEN_PASSED.get().getNode());
                    approval.setApprovalStage(ProjectStatusEnum.THE_ONSITE_DEMONSTRATION_HAS_BEEN_PASSED.get().getStage());
                    projectManagement.setIsState(ProjectStatusEnum.REVIEW_OF_THIRD_PARTY_APPROVAL_RESULTS_TO_BE_REVIEWED.get().getStatus());
                    projectManagement.setNode(ProjectStatusEnum.REVIEW_OF_THIRD_PARTY_APPROVAL_RESULTS_TO_BE_REVIEWED.get().getNode());
                    projectManagement.setStag(ProjectStatusEnum.REVIEW_OF_THIRD_PARTY_APPROVAL_RESULTS_TO_BE_REVIEWED.get().getStage());
                    //新增三方审批进程
                    Approval approvalSite = new Approval(IdUtils.snowId(),projectManagement.getProId(),ProjectStatusEnum.REVIEW_OF_THIRD_PARTY_APPROVAL_RESULTS_TO_BE_REVIEWED.get().getStage(),
                            ProjectStatusEnum.REVIEW_OF_THIRD_PARTY_APPROVAL_RESULTS_TO_BE_REVIEWED.get().getNode(),LocalDateTime.now(),null,null,ProjectStatusEnum.REVIEW_OF_THIRD_PARTY_APPROVAL_RESULTS_TO_BE_REVIEWED.get().getStatus(),
                            "/",null, null,null, LocalDateTime.now(),Approval.APPROVAL_TYPE_PROJECT_MANAGE);
                    approvalList.add(approvalSite);
                    reviewTask.setNode(ProjectStatusEnum.REVIEW_OF_THIRD_PARTY_APPROVAL_RESULTS_TO_BE_REVIEWED.get().getNode());
                    reviewTask.setNodeStatus(ProjectStatusEnum.REVIEW_OF_THIRD_PARTY_APPROVAL_RESULTS_TO_BE_REVIEWED.get().getStatus());
                } else if(Constants.ON_SITE_DEMONSTRATION_RETURN_RESTATEMENT.equals(dto.getApprovalStatus())){
                    //退回重申
                    approval.setApprovalNode(ProjectStatusEnum.ON_SITE_DEMONSTRATION_RETURN_RESTATEMENT.get().getNode());
                    approval.setApprovalStage(ProjectStatusEnum.ON_SITE_DEMONSTRATION_RETURN_RESTATEMENT.get().getStage());
                    projectManagement.setIsState(ProjectStatusEnum.REVIEW_OF_THIRD_PARTY_APPROVAL_RESULTS_TO_BE_REVIEWED.get().getStatus());
                    projectManagement.setNode(ProjectStatusEnum.REVIEW_OF_THIRD_PARTY_APPROVAL_RESULTS_TO_BE_REVIEWED.get().getNode());
                    projectManagement.setStag(ProjectStatusEnum.REVIEW_OF_THIRD_PARTY_APPROVAL_RESULTS_TO_BE_REVIEWED.get().getStage());
                    reviewTask.setNode(ProjectStatusEnum.REVIEW_OF_THIRD_PARTY_APPROVAL_RESULTS_TO_BE_REVIEWED.get().getNode());
                    reviewTask.setNodeStatus(ProjectStatusEnum.REVIEW_OF_THIRD_PARTY_APPROVAL_RESULTS_TO_BE_REVIEWED.get().getStatus());
                    //新增三方审批进程
                    Approval approvalSite = new Approval(IdUtils.snowId(),projectManagement.getProId(),ProjectStatusEnum.REVIEW_OF_THIRD_PARTY_APPROVAL_RESULTS_TO_BE_REVIEWED.get().getStage(),
                            ProjectStatusEnum.REVIEW_OF_THIRD_PARTY_APPROVAL_RESULTS_TO_BE_REVIEWED.get().getNode(),LocalDateTime.now(),null,nickName,ProjectStatusEnum.REVIEW_OF_THIRD_PARTY_APPROVAL_RESULTS_TO_BE_REVIEWED.get().getStatus(),
                            "/",null, null,null, LocalDateTime.now(),Approval.APPROVAL_TYPE_PROJECT_MANAGE);
                    approvalList.add(approvalSite);
                    //通过需修改
                }
                else if(Constants.ON_SITE_DEMONSTRATION_NEEDS_TO_BE_MODIFIED.equals(dto.getApprovalStatus())){
                    approval.setApprovalNode(ProjectStatusEnum.ON_SITE_DEMONSTRATION_NEEDS_TO_BE_MODIFIED.get().getNode());
                    approval.setApprovalStage(ProjectStatusEnum.ON_SITE_DEMONSTRATION_NEEDS_TO_BE_MODIFIED.get().getStage());
                    projectManagement.setIsState(ProjectStatusEnum.REVIEW_OF_THIRD_PARTY_APPROVAL_RESULTS_TO_BE_REVIEWED.get().getStatus());
                    projectManagement.setNode(ProjectStatusEnum.REVIEW_OF_THIRD_PARTY_APPROVAL_RESULTS_TO_BE_REVIEWED.get().getNode());
                    projectManagement.setStag(ProjectStatusEnum.REVIEW_OF_THIRD_PARTY_APPROVAL_RESULTS_TO_BE_REVIEWED.get().getStage());
                    reviewTask.setNode(ProjectStatusEnum.REVIEW_OF_THIRD_PARTY_APPROVAL_RESULTS_TO_BE_REVIEWED.get().getNode());
                    reviewTask.setNodeStatus(ProjectStatusEnum.REVIEW_OF_THIRD_PARTY_APPROVAL_RESULTS_TO_BE_REVIEWED.get().getStatus());
                    //新增三方审批进程
                    Approval approvalSite = new Approval(IdUtils.snowId(),projectManagement.getProId(),ProjectStatusEnum.REVIEW_OF_THIRD_PARTY_APPROVAL_RESULTS_TO_BE_REVIEWED.get().getStage(),
                            ProjectStatusEnum.REVIEW_OF_THIRD_PARTY_APPROVAL_RESULTS_TO_BE_REVIEWED.get().getNode(),LocalDateTime.now(),null,nickName,ProjectStatusEnum.REVIEW_OF_THIRD_PARTY_APPROVAL_RESULTS_TO_BE_REVIEWED.get().getStatus(),
                            "/",null, null,null, LocalDateTime.now(),Approval.APPROVAL_TYPE_PROJECT_MANAGE);
                    approvalList.add(approvalSite);
                }
            }else {
                if(Constants.THE_ONSITE_DEMONSTRATION_HAS_BEEN_PASSED.equals(dto.getApprovalStatus())){
                    //未转第三方
                    approval.setApprovalNode(ProjectStatusEnum.THE_ONSITE_DEMONSTRATION_HAS_BEEN_PASSED.get().getNode());
                    approval.setApprovalStage(ProjectStatusEnum.THE_ONSITE_DEMONSTRATION_HAS_BEEN_PASSED.get().getStage());
                    projectManagement.setIsState(ProjectStatusEnum.FINANCIAL_APPROVAL_AND_FILING_TO_BE_REVIEWED.get().getStatus());
                    projectManagement.setNode(ProjectStatusEnum.FINANCIAL_APPROVAL_AND_FILING_TO_BE_REVIEWED.get().getNode());
                    projectManagement.setStag(ProjectStatusEnum.FINANCIAL_APPROVAL_AND_FILING_TO_BE_REVIEWED.get().getStage());
                    //新增项目发改/财政审批备案进程
                    Approval approvalSite = new Approval(IdUtils.snowId(),projectManagement.getProId(),ProjectStatusEnum.FINANCIAL_APPROVAL_AND_FILING_TO_BE_REVIEWED.get().getStage(),
                            ProjectStatusEnum.FINANCIAL_APPROVAL_AND_FILING_TO_BE_REVIEWED.get().getNode(),LocalDateTime.now(),null,null,ProjectStatusEnum.FINANCIAL_APPROVAL_AND_FILING_TO_BE_REVIEWED.get().getStatus(),
                            "/",null, null,null, LocalDateTime.now(),Approval.APPROVAL_TYPE_PROJECT_MANAGE);
                    approvalList.add(approvalSite);
                    reviewTask.setNode(ProjectStatusEnum.FINANCIAL_APPROVAL_AND_FILING_TO_BE_REVIEWED.get().getNode());
                    reviewTask.setNodeStatus(ProjectStatusEnum.FINANCIAL_APPROVAL_AND_FILING_TO_BE_REVIEWED.get().getStatus());
                    reviewTask.setExpertStatus(ReviewTask.EXTRACT_STATUS_NOT_EVALUATE);
                    //现场论证通过，每个专家更新现场论证为已结束
                    ReviewTaskDetailVo reviewTaskDetailVo = reviewTaskService.reviewTaskDetailByProId(projectManagement.getProId());
                    Assert.isTrue(StringUtils.isNotNull(reviewTaskDetailVo),"未找到该项目的评审任务");
                    List<ExtractExpertDetailVo> extractExpertList = reviewTaskDetailVo.getExtractExpertList();
                    List<Approval> approvalArrayList = new ArrayList<>();
                    extractExpertList.stream().forEach(s->{
                        Approval expertApproval = approvalService.getApproval(projectManagement.getProId(), ProjectStatusEnum.ON_SITE_DEMONSTRATION_TO_BE_REVIEWED.get().getStatus(), s.getExpertId(), null);
                        expertApproval.setEndTime(LocalDateTime.now());
                        expertApproval.setApprovalStatus(ProjectStatusEnum.THE_ONSITE_DEMONSTRATION_HAS_BEEN_PASSED.get().getStatus());
                        expertApproval.setApprovalResult("通过");
                        approvalArrayList.add(expertApproval);
                    });
                    approvalService.saveOrUpdateBatch(approvalArrayList);
                    //抽取表下所有抽取出的状态为已结束
                    List<ExtractExpert> arrayList = new ArrayList<>();
                    List<ExtractExpert> extractExperts = reviewTaskService.getExtractExpertList(reviewTaskId);
                    Assert.isTrue(StringUtils.isNotEmpty(extractExperts),"该评审任务未找到专家抽取表信息");
                    extractExperts.stream().forEach(s->{
                        ExtractExpert expert = new ExtractExpert();
                        BeanUtils.copyProperties(s,expert);
                        expert.setStatus(ExtractExpert.STATUS_FINISH);
                        expert.setExtractNode(Constants.THE_ONSITE_DEMONSTRATION_HAS_BEEN_PASSED);
                        arrayList.add(expert);
                    });
                    extractExpertService.saveOrUpdateBatch(arrayList);
                    //同步项目数据到项目信息表中
                    synchronizationProjectInfo(projectManagement);
                    //退回重申：项目状态为现场论证退回重申
                }else if(Constants.ON_SITE_DEMONSTRATION_RETURN_RESTATEMENT.equals(dto.getApprovalStatus())){
                    approval.setApprovalNode(ProjectStatusEnum.ON_SITE_DEMONSTRATION_RETURN_RESTATEMENT.get().getNode());
                    approval.setApprovalStage(ProjectStatusEnum.ON_SITE_DEMONSTRATION_RETURN_RESTATEMENT.get().getStage());
                    approval.setEndTime(null);
                    projectManagement.setIsState(ProjectStatusEnum.ON_SITE_DEMONSTRATION_RETURN_RESTATEMENT.get().getStatus());
                    projectManagement.setNode(ProjectStatusEnum.ON_SITE_DEMONSTRATION_RETURN_RESTATEMENT.get().getNode());
                    projectManagement.setStag(ProjectStatusEnum.ON_SITE_DEMONSTRATION_RETURN_RESTATEMENT.get().getStage());

                    //同步评审任务节点
                    reviewTask.setNode(ProjectStatusEnum.ON_SITE_DEMONSTRATION_RETURN_RESTATEMENT.get().getNode());
                    reviewTask.setNodeStatus(ProjectStatusEnum.ON_SITE_DEMONSTRATION_RETURN_RESTATEMENT.get().getStatus());

                    //通过需修改：新增审核进程方案修改审核待提交、更新审核进程为现场论证通过需修改、同步项目和评审任务状态为方案修改审核待提交
                }else if(Constants.ON_SITE_DEMONSTRATION_NEEDS_TO_BE_MODIFIED.equals(dto.getApprovalStatus())){
                    approval.setApprovalNode(ProjectStatusEnum.ON_SITE_DEMONSTRATION_NEEDS_TO_BE_MODIFIED.get().getNode());
                    approval.setApprovalStage(ProjectStatusEnum.ON_SITE_DEMONSTRATION_NEEDS_TO_BE_MODIFIED.get().getStage());
                    approval.setEndTime(null);
                    projectManagement.setIsState(ProjectStatusEnum.ON_SITE_DEMONSTRATION_NEEDS_TO_BE_MODIFIED.get().getStatus());
                    projectManagement.setNode(ProjectStatusEnum.ON_SITE_DEMONSTRATION_NEEDS_TO_BE_MODIFIED.get().getNode());
                    projectManagement.setStag(ProjectStatusEnum.ON_SITE_DEMONSTRATION_NEEDS_TO_BE_MODIFIED.get().getStage());
                    reviewTask.setNode(ProjectStatusEnum.ON_SITE_DEMONSTRATION_NEEDS_TO_BE_MODIFIED.get().getNode());
                    reviewTask.setNodeStatus(ProjectStatusEnum.ON_SITE_DEMONSTRATION_NEEDS_TO_BE_MODIFIED.get().getStatus());

                    //评审任务下的专家、抽取状态、评审任务状态为现场论证已结束
                    reviewTask.setExpertStatus(ReviewTask.EXTRACT_STATUS_NOT_EVALUATE);
                    ReviewTaskDetailVo reviewTaskDetailVo = reviewTaskService.reviewTaskDetailByProId(projectManagement.getProId());
                    Assert.isTrue(StringUtils.isNotNull(reviewTaskDetailVo),"未找到该项目的评审任务");
                    List<ExtractExpertDetailVo> extractExpertList = reviewTaskDetailVo.getExtractExpertList();
                    List<Approval> approvalArrayList = new ArrayList<>();
                    extractExpertList.stream().forEach(s->{
                        Approval expertApproval = approvalService.getApproval(projectManagement.getProId(), ProjectStatusEnum.ON_SITE_DEMONSTRATION_TO_BE_REVIEWED.get().getStatus(), s.getExpertId(), null);
                        expertApproval.setEndTime(LocalDateTime.now());
                        expertApproval.setApprovalStatus(ProjectStatusEnum.THE_ONSITE_DEMONSTRATION_HAS_BEEN_PASSED.get().getStatus());
                        expertApproval.setApprovalResult("通过");
                        approvalArrayList.add(expertApproval);
                    });
                    approvalService.saveOrUpdateBatch(approvalArrayList);
                    //抽取表下所有抽取出的状态为已结束
                    List<ExtractExpert> arrayList = new ArrayList<>();
                    List<ExtractExpert> extractExperts = reviewTaskService.getExtractExpertList(reviewTaskId);
                    Assert.isTrue(StringUtils.isNotEmpty(extractExperts),"该评审任务未找到专家抽取表信息");
                    extractExperts.stream().forEach(s->{
                        ExtractExpert expert = new ExtractExpert();
                        BeanUtils.copyProperties(s,expert);
                        expert.setStatus(ExtractExpert.STATUS_FINISH);
                        expert.setExtractNode(Constants.THE_ONSITE_DEMONSTRATION_HAS_BEEN_PASSED);
                        arrayList.add(expert);
                    });
                    extractExpertService.saveOrUpdateBatch(arrayList);

                }
            }
            approval.setApprovalOperator(nickName);
            reviewTaskService.updateById(reviewTask);
        }
        //方案修改审核
        if(ProjectStatusEnum.SCHEME_DECLARATION_UPDATE_TO_BE_APPROVED.get().getStatus().equals(projectManagementService.getById(dto.getProjectId()).getIsState())) {
            Long reviewTaskId = projectManagement.getReviewTaskId();
            Assert.isTrue(StringUtils.isNotNull(reviewTaskId), "项目未关联相关评审任务");
            ReviewTask reviewTask = reviewTaskService.getById(reviewTaskId);
            //通过：更新审核进程为方案修改通过、新增审核进程为发改/财政待提交审核进程、更新项目状态、评审任务状态为发改/财政审核待提交
            if (ProjectStatusEnum.SCHEME_DECLARATION_UPDATE_PASSED.get().getStatus().equals(dto.getApprovalStatus())) {
                approval.setApprovalNode(ProjectStatusEnum.SCHEME_DECLARATION_UPDATE_PASSED.get().getNode());
                approval.setApprovalStage(ProjectStatusEnum.SCHEME_DECLARATION_UPDATE_PASSED.get().getStage());
                projectManagement.setIsState(ProjectStatusEnum.FINANCIAL_APPROVAL_AND_FILING_TO_BE_REVIEWED.get().getStatus());
                projectManagement.setNode(ProjectStatusEnum.FINANCIAL_APPROVAL_AND_FILING_TO_BE_REVIEWED.get().getNode());
                projectManagement.setStag(ProjectStatusEnum.FINANCIAL_APPROVAL_AND_FILING_TO_BE_REVIEWED.get().getStage());
                reviewTask.setNode(ProjectStatusEnum.FINANCIAL_APPROVAL_AND_FILING_TO_BE_REVIEWED.get().getNode());
                reviewTask.setNodeStatus(ProjectStatusEnum.FINANCIAL_APPROVAL_AND_FILING_TO_BE_REVIEWED.get().getStatus());
                Approval approvalSite = new Approval(IdUtils.snowId(), projectManagement.getProId(), ProjectStatusEnum.FINANCIAL_APPROVAL_AND_FILING_TO_BE_REVIEWED.get().getStage(),
                        ProjectStatusEnum.FINANCIAL_APPROVAL_AND_FILING_TO_BE_REVIEWED.get().getNode(), LocalDateTime.now(), null, null, ProjectStatusEnum.FINANCIAL_APPROVAL_AND_FILING_TO_BE_REVIEWED.get().getStatus(),
                        "/", null, null, null, LocalDateTime.now(), Approval.APPROVAL_TYPE_PROJECT_MANAGE);
                approvalList.add(approvalSite);
                //同步项目数据到项目信息表中
                synchronizationProjectInfo(projectManagement);
                //通过需修改：新增审核进程方案修改审核待提交、更新审核进程为现场论证通过需修改、同步项目和评审任务状态为方案修改审核待提交
            }else if (ProjectStatusEnum.SCHEME_DECLARATION_UPDATE_RETURN_MODIFICATION.get().getStatus().equals(dto.getApprovalStatus())) {
                approval.setApprovalNode(ProjectStatusEnum.SCHEME_DECLARATION_UPDATE_RETURN_MODIFICATION.get().getNode());
                approval.setApprovalStage(ProjectStatusEnum.SCHEME_DECLARATION_UPDATE_RETURN_MODIFICATION.get().getStage());
                approval.setEndTime(null);
                projectManagement.setIsState(ProjectStatusEnum.SCHEME_DECLARATION_UPDATE_RETURN_MODIFICATION.get().getStatus());
                projectManagement.setNode(ProjectStatusEnum.SCHEME_DECLARATION_UPDATE_RETURN_MODIFICATION.get().getNode());
                projectManagement.setStag(ProjectStatusEnum.SCHEME_DECLARATION_UPDATE_RETURN_MODIFICATION.get().getStage());
                reviewTask.setNode(ProjectStatusEnum.SCHEME_DECLARATION_UPDATE_RETURN_MODIFICATION.get().getNode());
                reviewTask.setNodeStatus(ProjectStatusEnum.SCHEME_DECLARATION_UPDATE_RETURN_MODIFICATION.get().getStatus());

            }
            reviewTaskService.updateById(reviewTask);
        }
        //三方论证审核
        if(ProjectStatusEnum.REVIEW_OF_THIRD_PARTY_APPROVAL_RESULTS_TO_BE_REVIEWED.get().getStatus().equals(projectManagementService.getById(dto.getProjectId()).getIsState())){
            Long reviewTaskId = projectManagement.getReviewTaskId();
            Assert.isTrue(StringUtils.isNotNull(reviewTaskId),"项目未关联相关评审任务");
            ReviewTask reviewTask = reviewTaskService.getById(reviewTaskId);
            //获取上一条审核进程的节点状态
            QueryWrapper<Approval> approvalQueryWrapper = new QueryWrapper<>();
            approvalQueryWrapper.eq("project_id",projectManagement.getProId())
                    .eq("del_flag",Constants.DELETE_STATUS_NORMAL)
                    .eq("approval_type",Approval.APPROVAL_TYPE_PROJECT_MANAGE)
                    .orderByDesc("create_time");
            List<Approval> approvals = approvalMapper.selectList(approvalQueryWrapper);
            if (approvals.get(1).getApprovalStatus().equals(ProjectStatusEnum.THE_ONSITE_DEMONSTRATION_HAS_BEEN_PASSED.get().getStatus())) {
                //现场论证为通过
                if (Constants.REVIEW_OF_THIRD_PARTY_APPROVAL_RESULTS_HAS_BEEN_PASSED.equals(dto.getApprovalStatus())) {
                    //三方审批结果审核 结果为通过
                    approval.setApprovalNode(ProjectStatusEnum.REVIEW_OF_THIRD_PARTY_APPROVAL_RESULTS_HAS_BEEN_PASSED.get().getNode());
                    approval.setApprovalStage(ProjectStatusEnum.REVIEW_OF_THIRD_PARTY_APPROVAL_RESULTS_HAS_BEEN_PASSED.get().getStage());

                    //新增发改/财政审批备案进程
                    Approval approvalSite =new Approval(IdUtils.snowId(),projectManagement.getProId(),ProjectStatusEnum.FINANCIAL_APPROVAL_AND_FILING_TO_BE_REVIEWED.get().getStage(),
                            ProjectStatusEnum.FINANCIAL_APPROVAL_AND_FILING_TO_BE_REVIEWED.get().getNode(),LocalDateTime.now(),null,null,ProjectStatusEnum.FINANCIAL_APPROVAL_AND_FILING_TO_BE_REVIEWED.get().getStatus(),
                            "/",null, null,null, LocalDateTime.now(),Approval.APPROVAL_TYPE_PROJECT_MANAGE);
                    approvalList.add(approvalSite);
                    //同步项目的节点为发改/财政审批备案
                    projectManagement.setIsState(ProjectStatusEnum.FINANCIAL_APPROVAL_AND_FILING_TO_BE_REVIEWED.get().getStatus());
                    projectManagement.setNode(ProjectStatusEnum.FINANCIAL_APPROVAL_AND_FILING_TO_BE_REVIEWED.get().getNode());
                    projectManagement.setStag(ProjectStatusEnum.FINANCIAL_APPROVAL_AND_FILING_TO_BE_REVIEWED.get().getStage());
                    reviewTask.setNode(ProjectStatusEnum.FINANCIAL_APPROVAL_AND_FILING_TO_BE_REVIEWED.get().getNode());
                    reviewTask.setNodeStatus(ProjectStatusEnum.FINANCIAL_APPROVAL_AND_FILING_TO_BE_REVIEWED.get().getStatus());
                    //评审任务下的专家、抽取状态、评审任务状态为现场论证已结束
                    reviewTask.setExpertStatus(ReviewTask.EXTRACT_STATUS_NOT_EVALUATE);
                    ReviewTaskDetailVo reviewTaskDetailVo = reviewTaskService.reviewTaskDetailByProId(projectManagement.getProId());
                    Assert.isTrue(StringUtils.isNotNull(reviewTaskDetailVo),"未找到该项目的评审任务");
                    List<ExtractExpertDetailVo> extractExpertList = reviewTaskDetailVo.getExtractExpertList();
                    List<Approval> approvalArrayList = new ArrayList<>();
                    extractExpertList.stream().forEach(s->{
                        Approval expertApproval = approvalService.getApproval(projectManagement.getProId(), ProjectStatusEnum.ON_SITE_DEMONSTRATION_TO_BE_REVIEWED.get().getStatus(), s.getExpertId(), null);
                        expertApproval.setEndTime(LocalDateTime.now());
                        expertApproval.setApprovalStatus(ProjectStatusEnum.THE_ONSITE_DEMONSTRATION_HAS_BEEN_PASSED.get().getStatus());
                        expertApproval.setApprovalResult("通过");
                        approvalArrayList.add(expertApproval);
                    });
                    approvalService.saveOrUpdateBatch(approvalArrayList);
                    //抽取表下所有抽取出的状态为已结束
                    List<ExtractExpert> arrayList = new ArrayList<>();
                    List<ExtractExpert> extractExperts = reviewTaskService.getExtractExpertList(reviewTaskId);
                    Assert.isTrue(StringUtils.isNotEmpty(extractExperts),"该评审任务未找到专家抽取表信息");
                    extractExperts.stream().forEach(s->{
                        ExtractExpert expert = new ExtractExpert();
                        BeanUtils.copyProperties(s,expert);
                        expert.setStatus(ExtractExpert.STATUS_FINISH);
                        expert.setExtractNode(Constants.THE_ONSITE_DEMONSTRATION_HAS_BEEN_PASSED);
                        arrayList.add(expert);
                    });
                    extractExpertService.saveOrUpdateBatch(arrayList);
                    //同步项目数据到项目信息表中
                    synchronizationProjectInfo(projectManagement);

                } else if (Constants.REVIEW_OF_THIRD_PARTY_APPROVAL_RESULTS_RETURN_RESTATEMENT.equals(dto.getApprovalStatus())) {
                    //三方审批结果审核 结果为退回重审
                    approval.setApprovalNode(ProjectStatusEnum.REVIEW_OF_THIRD_PARTY_APPROVAL_RESULTS_RETURN_RESTATEMENT.get().getNode());
                    approval.setApprovalStage(ProjectStatusEnum.REVIEW_OF_THIRD_PARTY_APPROVAL_RESULTS_RETURN_RESTATEMENT.get().getStage());
                    //新增现场论证进程
                    Approval approvalSite = new Approval(IdUtils.snowId(),projectManagement.getProId(),ProjectStatusEnum.ON_SITE_DEMONSTRATION_TO_BE_REVIEWED.get().getStage(),
                            ProjectStatusEnum.ON_SITE_DEMONSTRATION_TO_BE_REVIEWED.get().getNode(),LocalDateTime.now(),null,nickName,ProjectStatusEnum.ON_SITE_DEMONSTRATION_TO_BE_REVIEWED.get().getStatus(),
                            "/",null, null,null, LocalDateTime.now(),Approval.APPROVAL_TYPE_PROJECT_MANAGE);
                    approvalList.add(approvalSite);

                    projectManagement.setIsState(ProjectStatusEnum.ON_SITE_DEMONSTRATION_TO_BE_REVIEWED.get().getStatus());
                    projectManagement.setNode(ProjectStatusEnum.ON_SITE_DEMONSTRATION_TO_BE_REVIEWED.get().getNode());
                    projectManagement.setStag(ProjectStatusEnum.ON_SITE_DEMONSTRATION_TO_BE_REVIEWED.get().getStage());
                    //同步评审任务节点
                    reviewTask.setNode(ProjectStatusEnum.ON_SITE_DEMONSTRATION_TO_BE_REVIEWED.get().getNode());
                    reviewTask.setNodeStatus(ProjectStatusEnum.ON_SITE_DEMONSTRATION_TO_BE_REVIEWED.get().getStatus());
                }
            } else if (approvals.get(1).getApprovalStatus().equals(ProjectStatusEnum.ON_SITE_DEMONSTRATION_RETURN_RESTATEMENT.get().getStatus())) {
                //现场论证为退回重申
                if (Constants.REVIEW_OF_THIRD_PARTY_APPROVAL_RESULTS_HAS_BEEN_PASSED.equals(dto.getApprovalStatus())) {
                    //三方审批结果审核 结果为通过
                    approval.setApprovalNode(ProjectStatusEnum.REVIEW_OF_THIRD_PARTY_APPROVAL_RESULTS_HAS_BEEN_PASSED.get().getNode());
                    approval.setApprovalStage(ProjectStatusEnum.REVIEW_OF_THIRD_PARTY_APPROVAL_RESULTS_HAS_BEEN_PASSED.get().getStage());

                    //同步项目的节点为方案申报
                    projectManagement.setIsState(ProjectStatusEnum.REVIEW_OF_THIRD_PARTY_APPROVAL_RESULTS_HAS_BEEN_PASSED.get().getStatus());
                    projectManagement.setNode(ProjectStatusEnum.REVIEW_OF_THIRD_PARTY_APPROVAL_RESULTS_HAS_BEEN_PASSED.get().getNode());
                    projectManagement.setStag(ProjectStatusEnum.REVIEW_OF_THIRD_PARTY_APPROVAL_RESULTS_HAS_BEEN_PASSED.get().getStage());
                    reviewTask.setNode(ProjectStatusEnum.REVIEW_OF_THIRD_PARTY_APPROVAL_RESULTS_HAS_BEEN_PASSED.get().getNode());
                    reviewTask.setNodeStatus(ProjectStatusEnum.REVIEW_OF_THIRD_PARTY_APPROVAL_RESULTS_HAS_BEEN_PASSED.get().getStatus());

                } else if (Constants.REVIEW_OF_THIRD_PARTY_APPROVAL_RESULTS_RETURN_RESTATEMENT.equals(dto.getApprovalStatus())) {
                    //三方审批结果审核 结果为退回重审
                    approval.setApprovalNode(ProjectStatusEnum.REVIEW_OF_THIRD_PARTY_APPROVAL_RESULTS_RETURN_RESTATEMENT.get().getNode());
                    approval.setApprovalStage(ProjectStatusEnum.REVIEW_OF_THIRD_PARTY_APPROVAL_RESULTS_RETURN_RESTATEMENT.get().getStage());

                    //新增现场论证待审核进程
                    Approval approvalSite =new Approval(IdUtils.snowId(),projectManagement.getProId(),ProjectStatusEnum.ON_SITE_DEMONSTRATION_TO_BE_REVIEWED.get().getStage(),
                            ProjectStatusEnum.ON_SITE_DEMONSTRATION_TO_BE_REVIEWED.get().getNode(),LocalDateTime.now(),null,null,ProjectStatusEnum.ON_SITE_DEMONSTRATION_TO_BE_REVIEWED.get().getStatus(),
                            "/",null, null,null, LocalDateTime.now(),Approval.APPROVAL_TYPE_PROJECT_MANAGE);
                    approvalList.add(approvalSite);
                    //同步项目的节点为现场论证待审核
                    projectManagement.setIsState(ProjectStatusEnum.ON_SITE_DEMONSTRATION_TO_BE_REVIEWED.get().getStatus());
                    projectManagement.setNode(ProjectStatusEnum.ON_SITE_DEMONSTRATION_TO_BE_REVIEWED.get().getNode());
                    projectManagement.setStag(ProjectStatusEnum.ON_SITE_DEMONSTRATION_TO_BE_REVIEWED.get().getStage());
                    reviewTask.setNode(ProjectStatusEnum.ON_SITE_DEMONSTRATION_TO_BE_REVIEWED.get().getNode());
                    reviewTask.setNodeStatus(ProjectStatusEnum.ON_SITE_DEMONSTRATION_TO_BE_REVIEWED.get().getStatus());
                }
            } else if (approvals.get(1).getApprovalStatus().equals(ProjectStatusEnum.ON_SITE_DEMONSTRATION_NEEDS_TO_BE_MODIFIED.get().getStatus())) {
                //现场论证为通过需要修改
                if (Constants.REVIEW_OF_THIRD_PARTY_APPROVAL_RESULTS_HAS_BEEN_PASSED.equals(dto.getApprovalStatus())) {
                    //三方审批结果审核 结果为通过
                    approval.setApprovalNode(ProjectStatusEnum.REVIEW_OF_THIRD_PARTY_APPROVAL_RESULTS_HAS_BEEN_PASSED.get().getNode());
                    approval.setApprovalStage(ProjectStatusEnum.REVIEW_OF_THIRD_PARTY_APPROVAL_RESULTS_HAS_BEEN_PASSED.get().getStage());

                    //同步项目的节点为方案修改
                    projectManagement.setIsState(ProjectStatusEnum.REVIEW_OF_THIRD_PARTY_APPROVAL_RESULTS_HAS_BEEN_PASSED.get().getStatus());
                    projectManagement.setNode(ProjectStatusEnum.REVIEW_OF_THIRD_PARTY_APPROVAL_RESULTS_HAS_BEEN_PASSED.get().getNode());
                    projectManagement.setStag(ProjectStatusEnum.REVIEW_OF_THIRD_PARTY_APPROVAL_RESULTS_HAS_BEEN_PASSED.get().getStage());
                    reviewTask.setNode(ProjectStatusEnum.REVIEW_OF_THIRD_PARTY_APPROVAL_RESULTS_HAS_BEEN_PASSED.get().getNode());
                    reviewTask.setNodeStatus(ProjectStatusEnum.REVIEW_OF_THIRD_PARTY_APPROVAL_RESULTS_HAS_BEEN_PASSED.get().getStatus());
                    //评审任务下的专家、抽取状态、评审任务状态为现场论证已结束
                    reviewTask.setExpertStatus(ReviewTask.EXTRACT_STATUS_NOT_EVALUATE);
                    ReviewTaskDetailVo reviewTaskDetailVo = reviewTaskService.reviewTaskDetailByProId(projectManagement.getProId());
                    Assert.isTrue(StringUtils.isNotNull(reviewTaskDetailVo),"未找到该项目的评审任务");
                    List<ExtractExpertDetailVo> extractExpertList = reviewTaskDetailVo.getExtractExpertList();
                    List<Approval> approvalArrayList = new ArrayList<>();
                    extractExpertList.stream().forEach(s->{
                        Approval expertApproval = approvalService.getApproval(projectManagement.getProId(), ProjectStatusEnum.ON_SITE_DEMONSTRATION_TO_BE_REVIEWED.get().getStatus(), s.getExpertId(), null);
                        expertApproval.setEndTime(LocalDateTime.now());
                        expertApproval.setApprovalStatus(ProjectStatusEnum.THE_ONSITE_DEMONSTRATION_HAS_BEEN_PASSED.get().getStatus());
                        expertApproval.setApprovalResult("通过");
                        approvalArrayList.add(expertApproval);
                    });
                    approvalService.saveOrUpdateBatch(approvalArrayList);
                    //抽取表下所有抽取出的状态为已结束
                    List<ExtractExpert> arrayList = new ArrayList<>();
                    List<ExtractExpert> extractExperts = reviewTaskService.getExtractExpertList(reviewTaskId);
                    Assert.isTrue(StringUtils.isNotEmpty(extractExperts),"该评审任务未找到专家抽取表信息");
                    extractExperts.stream().forEach(s->{
                        ExtractExpert expert = new ExtractExpert();
                        BeanUtils.copyProperties(s,expert);
                        expert.setStatus(ExtractExpert.STATUS_FINISH);
                        expert.setExtractNode(Constants.THE_ONSITE_DEMONSTRATION_HAS_BEEN_PASSED);
                        arrayList.add(expert);
                    });
                    extractExpertService.saveOrUpdateBatch(arrayList);
                } else if (Constants.REVIEW_OF_THIRD_PARTY_APPROVAL_RESULTS_RETURN_RESTATEMENT.equals(dto.getApprovalStatus())) {
                    //三方审批结果审核 结果为退回重审
                    approval.setApprovalNode(ProjectStatusEnum.REVIEW_OF_THIRD_PARTY_APPROVAL_RESULTS_RETURN_RESTATEMENT.get().getNode());
                    approval.setApprovalStage(ProjectStatusEnum.REVIEW_OF_THIRD_PARTY_APPROVAL_RESULTS_RETURN_RESTATEMENT.get().getStage());

                    //新增现场论证待审核进程
                    Approval approvalSite =new Approval(IdUtils.snowId(),projectManagement.getProId(),ProjectStatusEnum.ON_SITE_DEMONSTRATION_TO_BE_REVIEWED.get().getStage(),
                            ProjectStatusEnum.ON_SITE_DEMONSTRATION_TO_BE_REVIEWED.get().getNode(),LocalDateTime.now(),null,null,ProjectStatusEnum.ON_SITE_DEMONSTRATION_TO_BE_REVIEWED.get().getStatus(),
                            "/",null, null,null, LocalDateTime.now(),Approval.APPROVAL_TYPE_PROJECT_MANAGE);
                    approvalList.add(approvalSite);
                    //同步项目的节点为现场论证待审核
                    projectManagement.setIsState(ProjectStatusEnum.ON_SITE_DEMONSTRATION_TO_BE_REVIEWED.get().getStatus());
                    projectManagement.setNode(ProjectStatusEnum.ON_SITE_DEMONSTRATION_TO_BE_REVIEWED.get().getNode());
                    projectManagement.setStag(ProjectStatusEnum.ON_SITE_DEMONSTRATION_TO_BE_REVIEWED.get().getStage());
                    reviewTask.setNode(ProjectStatusEnum.ON_SITE_DEMONSTRATION_TO_BE_REVIEWED.get().getNode());
                    reviewTask.setNodeStatus(ProjectStatusEnum.ON_SITE_DEMONSTRATION_TO_BE_REVIEWED.get().getStatus());
                }
            }
            reviewTaskService.updateById(reviewTask);
        }
        //合规审查审核
        if(ProjectStatusEnum.COMPLIANCE_REVIEW_TO_BE_REVIEWED.get().getStatus().equals(projectManagementService.getById(dto.getProjectId()).getIsState())){
            Long reviewTaskId = projectManagement.getReviewTaskId();
            Assert.isTrue(StringUtils.isNotNull(reviewTaskId),"项目未关联相关评审任务");
            ReviewTask reviewTask = reviewTaskService.getById(reviewTaskId);
            //通过  新增通过进程
            if(ProjectStatusEnum.COMPLIANCE_REVIEW_HAS_BEEN_PASSED.get().getStatus().equals(dto.getApprovalStatus())) {
                //新增初验备案进程
                Approval approvalResult = new Approval(IdUtils.snowId(),projectManagement.getProId(),ProjectStatusEnum.PRELIMINARY_INSPECTION_AND_FILING_TO_BE_SUBMITTED.get().getStage(),
                        ProjectStatusEnum.PRELIMINARY_INSPECTION_AND_FILING_TO_BE_SUBMITTED.get().getNode(),LocalDateTime.now(),null,null,ProjectStatusEnum.PRELIMINARY_INSPECTION_AND_FILING_TO_BE_SUBMITTED.get().getStatus(),
                        "/",null, null,null, LocalDateTime.now(),Approval.APPROVAL_TYPE_PROJECT_MANAGE);
                approvalList.add(approvalResult);
                //同步项目节点为初验备案
                approval.setApprovalNode(ProjectStatusEnum.COMPLIANCE_REVIEW_HAS_BEEN_PASSED.get().getNode());
                approval.setApprovalStage(ProjectStatusEnum.COMPLIANCE_REVIEW_HAS_BEEN_PASSED.get().getStage());
                projectManagement.setIsState(ProjectStatusEnum.PRELIMINARY_INSPECTION_AND_FILING_TO_BE_SUBMITTED.get().getStatus());
                projectManagement.setNode(ProjectStatusEnum.PRELIMINARY_INSPECTION_AND_FILING_TO_BE_SUBMITTED.get().getNode());
                projectManagement.setStag(ProjectStatusEnum.PRELIMINARY_INSPECTION_AND_FILING_TO_BE_SUBMITTED.get().getStage());
                reviewTask.setNode(ProjectStatusEnum.PRELIMINARY_INSPECTION_AND_FILING_TO_BE_SUBMITTED.get().getNode());
                reviewTask.setNodeStatus(ProjectStatusEnum.PRELIMINARY_INSPECTION_AND_FILING_TO_BE_SUBMITTED.get().getStatus());
                //同步项目数据到项目信息表中
                synchronizationProjectInfo(projectManagement);
            }else if(ProjectStatusEnum.COMPLIANCE_REVIEW_REJECTED.get().getStatus().equals(dto.getApprovalStatus())){
                //驳回 新增驳回审核进程合规审核待提交 同步项目状态为合规审查待提交
                approval.setApprovalNode(ProjectStatusEnum.COMPLIANCE_REVIEW_REJECTED.get().getNode());
                approval.setApprovalStage(ProjectStatusEnum.COMPLIANCE_REVIEW_REJECTED.get().getStage());
                approval.setApprovalOperator(nickName);
                approval.setEndTime(null);
                projectManagement.setIsState(ProjectStatusEnum.COMPLIANCE_REVIEW_REJECTED.get().getStatus());
                projectManagement.setNode(ProjectStatusEnum.COMPLIANCE_REVIEW_REJECTED.get().getNode());
                projectManagement.setStag(ProjectStatusEnum.COMPLIANCE_REVIEW_REJECTED.get().getStage());
                reviewTask.setNode(ProjectStatusEnum.COMPLIANCE_REVIEW_REJECTED.get().getNode());
                reviewTask.setNodeStatus(ProjectStatusEnum.COMPLIANCE_REVIEW_REJECTED.get().getStatus());
            }
            reviewTaskService.updateById(reviewTask);
        }
        //重新安排评审会议
        if (ProjectStatusEnum.ONLINE_PREQUALIFICATION_PENDING_ARRANGE.get().getStatus().equals(dto.getApprovalStatus())) {
            ReviewTask reviewTask = reviewTaskService.getById(projectManagement.getReviewTaskId());
            returnOfComment(approval, projectManagement, reviewTask, approvalList);
        }
        approvalService.updateById(approval);

        //批量插入审核进程
        if(!Collections.isEmpty(approvalList)){
            approvalMapper.batchApproval(approvalList);
        }
        projectManagement.setUpdateTime(LocalDateTime.now());
        return projectManagementService.updateById(projectManagement);
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public List<OnLineVo> onLinePreliminary(Long proId,String createTime) {

        List<OnLineVo> lineVos = approvalMapper.onLinePreliminary(proId,createTime);
        lineVos.stream().forEach(s->{
            if (StringUtils.isNotEmpty(s.getApprovalDatabase())){
                YzqFile file = fileService.getById(s.getApprovalDatabase());
                if (StringUtils.isNotNull(file)){
                    s.setApprovalDatabaseFile(file);
                }
            }
            if(StringUtils.isNotEmpty(s.getStatus())){
                if(s.getStatus().equals(ProjectStatusEnum.ONLINE_PREQUALIFICATION_APPROVED.get().getStatus())
//                        || s.getStatus().equals(ProjectStatusEnum.ON_SITE_DEMONSTRATION_lAPPLY_CANCEL.get().getStatus())
                ){
                    s.setStatus("已审批");
                }else {
                    s.setStatus("未审批");
                }
            }

        });
        return lineVos;
    }
    @Override
    public Approval plan(Long projectId) {
        return approvalMapper.plan(projectId);
    }

    @Override
    public Approval dealStayApproval(Long proId,String status,String approvalStatus,String approvalDatabase,Long expertId, Long planId, String approvalOperator) {
        ProjectManagement projectManagement = projectManagementService.getById(proId);
        Assert.isTrue(StringUtils.isNotNull(projectManagement),"处理审核进程：项目id有误，未找到该项目");
        ApproveProgressVo anEnum = ProjectStatusEnum.getEnum(approvalStatus);
        Assert.isTrue(StringUtils.isNotNull(anEnum),"处理审核进程：未找到该状态对应的项目枚举对象");
        if(StringUtils.isNull(expertId)){
            projectManagement.setIsState(approvalStatus);
            projectManagement.setStag(anEnum.getStage());
            projectManagement.setNode(anEnum.getNode());
            projectManagementService.updateById(projectManagement);
        }
        Approval approval = approvalMapper.getApproval( proId,  status, expertId,  planId);
        Assert.isTrue(StringUtils.isNotNull(approval),"未找到该审核状态对应的审核记录");
        if (StringUtils.isNotEmpty(approvalDatabase)){
            approval.setApprovalDatabase(approvalDatabase);
        }if (StringUtils.isNotEmpty(approvalOperator)){
            approval.setApprovalOperator(approvalOperator);
        }
        approval.setApprovalStatus(approvalStatus);
        approval.setApprovalStage(anEnum.getStage());
        approval.setApprovalNode(anEnum.getNode());
        approval.setEndTime(LocalDateTime.now());
        approvalMapper.updateById(approval);
        return approval;
    }

    @Override
    public Approval getApproval(Long proId, String approvalStatus,Long expertId, Long planId) {
        return approvalMapper.getApproval(proId, approvalStatus,expertId,planId);
    }

    @Override
    public int batchApproval(List<Approval> list) {
        return approvalMapper.batchApproval(list);
    }

    @Override
    public String getApprovalOpinion(Long approvalId) {
        Approval approval = approvalMapper.selectById(approvalId);
        LambdaQueryWrapper<Approval> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(Approval::getProjectId,approval.getProjectId())
                .eq(Approval::getDelFlag,Constants.DELETE_STATUS_NORMAL)
                .orderByAsc(Approval::getCreateTime);
        List<Approval> approvals = approvalMapper.selectList(queryWrapper);
        int i = 0;
        for (Approval a:approvals){
            if (a.getApprovalId().equals(approvalId)) {
                break;
            }
            i++;
        };
        return approvals.get(i-1).getApprovalOpinion();
    }

    /**
     *  退回重审:新增专家在线预审待审核进程，审核进程更新为意见汇总退出重申，项目状态为在线预审待审批
      * @param approval 审核进程
     * @param projectManagement  项目信息
     * @param reviewTask  评审任务信息
     * @param approvalList 审核集合
     */
    public  void returnOfComment(Approval approval,ProjectManagement projectManagement,ReviewTask reviewTask,List<Approval> approvalList){
        approval.setApprovalNode(ProjectStatusEnum.ONLINE_PREQUALIFICATION_PENDING_APPROVAL_AGAIN.get().getNode());
        approval.setApprovalStage(ProjectStatusEnum.ONLINE_PREQUALIFICATION_PENDING_APPROVAL_AGAIN.get().getStage());
        projectManagement.setIsState(ProjectStatusEnum.ONLINE_PREQUALIFICATION_PENDING_APPROVAL_AGAIN.get().getStatus());
        projectManagement.setNode(ProjectStatusEnum.ONLINE_PREQUALIFICATION_PENDING_APPROVAL_AGAIN.get().getNode());
        projectManagement.setStag(ProjectStatusEnum.ONLINE_PREQUALIFICATION_PENDING_APPROVAL_AGAIN.get().getStage());
        //同步评审任务节点
        reviewTask.setNode(ProjectStatusEnum.ONLINE_PREQUALIFICATION_PENDING_APPROVAL_AGAIN.get().getNode());
        reviewTask.setNodeStatus(ProjectStatusEnum.ONLINE_PREQUALIFICATION_PENDING_APPROVAL_AGAIN.get().getStatus());
        //新增多个专家在线预审进程
        List<ExtractExpertDetailVo> extractExpertList = reviewTaskService.reviewTaskDetailByTaskId(reviewTask.getReviewTaskId()).getExtractExpertList();
        extractExpertList.stream().forEach(s->{
            Approval approvalOnLine = new Approval(IdUtils.snowId(),projectManagement.getProId(),ProjectStatusEnum.ONLINE_PREQUALIFICATION_PENDING_APPROVAL.get().getStage(),
                    ProjectStatusEnum.ONLINE_PREQUALIFICATION_PENDING_APPROVAL.get().getNode(),LocalDateTime.now(),LocalDateTime.now(),SecurityUtils.getUsername(),ProjectStatusEnum.ONLINE_PREQUALIFICATION_PENDING_APPROVAL.get().getStatus(),
                    "/",null, null,null, LocalDateTime.now(),Approval.APPROVAL_TYPE_EXPERT,s.getExpertId(),null);
            approvalList.add(approvalOnLine);
        });
    }

    @Override
    public String lastApprovalResult(String expertId) {
        LambdaQueryWrapper<Approval> w = new LambdaQueryWrapper<>();
        w.eq(Approval::getExpertId, expertId).eq(Approval::getApprovalStatus,Constants.ONLINE_PREQUALIFICATION_APPROVED).orderByDesc(Approval::getCreateTime);
        List<Approval> approvals = baseMapper.selectList(w);
        if (StringUtils.isNotEmpty(approvals)){
            return approvals.get(0).getApprovalOpinion();
        }
        return null;
    }


    @Override
    public Approval getApprovalByCreateTime(Long proId, String approvalStatus,Long expertId, String approvalType,LocalDateTime createTime) {
        return approvalMapper.getApprovalByCreateTime(proId, approvalStatus,expertId,approvalType,createTime);
    }
}
